<?php

class View {
    public $jessiMsg = '';
    public $jessiFooterMsg = '';
    public $_tpl_vars = array();

    function __construct() {
       // echo 'this is the view';

    }

    public function getJessiMsg(){
        return $this->jessiMsg;
    }

    /**
     * @param $msg
     */
    public function setJessiMsg($msg){
        $this->jessiMsg = $msg;
    }


    public function getJessiFooterMsg(){
        return $this->jessiFooterMsg;
    }

    /**
     * @param $msg
     */
    public function setJessiFooterMsg($msg){
        $this->jessiFooterMsg = $msg;
    }



    
    /**
     * 
     * @param type $key
     * @param type $value
     */
    public function assign ($key, $value){
        $this->_tpl_vars[$key] = $value;
    }
    
    /**
     * 
     * @param type $key
     * @return type
     */
    public function getTplVar($key){
        $value = '';
        if (isset($this->_tpl_vars[$key])){
             $value = $this->_tpl_vars[$key];
        }
        return $value;
        
    }

    public function render($name, $noInclude = false)
    {
        
        
        
        if (!empty($this->jessiMsg)){
            $id = str_replace('/','',$name);
            $this->jessiMsg = '<div class="jessiMsgContainer" id="'.$id.'">'.$this->jessiMsg.'</div>';
        }

        if (!empty($this->jessiFooterMsgMsg)){
            $id = str_replace('/','',$name);
            $this->jessiMsg = '<div class="jessiFooterMsgContainer" id="'.$id.'">'.$this->jessiFooterMsg.'</div>';
        }

        if($noInclude){
            if(Helper::isJessi()){
                echo $this->jessiMsg;
            }
            require 'views/' . $name . '.php';
            if(Helper::isJessi()){
                echo $this->jessiFooterMsg;
            }
        }else{
            require 'views/header.php';
            if(Helper::isJessi()){
              echo $this->jessiMsg;
            }

            require 'views/' . $name . '.php';
            if(Helper::isJessi()){
              echo $this->jessiFooterMsg;
            }
            require 'views/footer.php';
        }

    }

}